import java.util.Scanner;

public class Game {

    public static void main(String[] args) {
	Player white = new Player(Color.WHITE);
	Player black = new Player(Color.BLACK);

	ChessBoard board = new ChessBoard();

	Scanner scan = new Scanner(System.in);

	boolean gameOn = true;
	boolean legalMove = false;
	int moveCount = 0;
	while( gameOn ) {
	    legalMove = false;
	    String move = null;
	    while( !legalMove ) {
		if( moveCount%2 == 0 ) {
		    board.printBoard();
		    System.out.print("WHITE move: ");
		    move = scan.nextLine();
		    int x1 = (int)(move.charAt(1) - '1');
		    int y1 = (int)(move.charAt(0) - 'a');
		    int x2 = (int)(move.charAt(4) - '1');
		    int y2 = (int)(move.charAt(3) - 'a');
		    legalMove = board.move(Color.WHITE,x1,y1,x2,y2);
		    if( !legalMove ) {
			System.err.println("Illegal move.  Try again.");
		    } else {
			moveCount++;
		    }
		} else {
		    board.printBoard();
		    System.out.print("BLACK move: ");
		    move = scan.nextLine();
		    int x1 = (int)(move.charAt(1) - '1');
		    int y1 = (int)(move.charAt(0) - 'a');
		    int x2 = (int)(move.charAt(4) - '1');
		    int y2 = (int)(move.charAt(3) - 'a');
		    legalMove = board.move(Color.BLACK,x1,y1,x2,y2);
		    if( !legalMove ) {
			System.err.println("Illegal move.  Try again.");
		    } else {
			moveCount++;
		    }
		}
	    }
	}

    }
				 

}
